package com.all.play.myapplication.view;

import android.app.Activity;
import android.app.Dialog;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.Display;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.EditText;

import com.all.play.myapplication.R;

/**
 * Created by 聪明一只哈 on 2018/4/19.
 * Time: 2018/4/19  16:15
 */

public class PducShowDialog extends Dialog {


    private Activity context;
    private View.OnClickListener mClickListener;
    private String name;
    private String cover_price;
    public EditText pduc_name;
    public EditText pdut_price;
    private Button bt_change;

    public PducShowDialog(Activity context, int theme, View.OnClickListener clickListener, String name, String cover_price) {
        super(context, theme);
        this.context = context;
        this.mClickListener = clickListener;
        this.name = name;
        this.cover_price = cover_price;
    }


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // 指定布局
        this.setContentView(R.layout.dialog_edit_pdut);

        pduc_name = (EditText) findViewById(R.id.pduc_name);
        pdut_price = (EditText) findViewById(R.id.pdut_price);

        if(!TextUtils.isEmpty(name)&&!TextUtils.isEmpty(cover_price)){
            pduc_name.setText(name);
            pdut_price.setText(cover_price);
        }



        /*
         * 获取圣诞框的窗口对象及参数对象以修改对话框的布局设置, 可以直接调用getWindow(),表示获得这个Activity的Window
         * 对象,这样这可以以同样的方式改变这个Activity的属性.
         */
        Window dialogWindow = this.getWindow();

        WindowManager m = context.getWindowManager();
        Display d = m.getDefaultDisplay(); // 获取屏幕宽、高用
        WindowManager.LayoutParams p = dialogWindow.getAttributes(); // 获取对话框当前的参数值
        // p.height = (int) (d.getHeight() * 0.6); // 高度设置为屏幕的0.6
        p.width = (int) (d.getWidth() * 0.8); // 宽度设置为屏幕的0.8
        dialogWindow.setAttributes(p);

        // 根据id在布局中找到控件对象
        bt_change = (Button) findViewById(R.id.bt_change);

        // 为按钮绑定点击事件监听器
        bt_change.setOnClickListener(mClickListener);

        this.setCancelable(true);
    }
}
